#!/usr/bin/bash
echo "erase - Remove an instance with a given unique ID. Note all data will be lost."
echo " "

if [ "$1" == help ] || [ "$#" -eq 0 ]
then
  echo "Usage: mh erase <id>"
  echo " "
  exit
fi

ID=$1

echo "WARNING!"
echo " "
mh deploy status | grep $ID
echo " "
echo "Instance $ID will be completely erased. All data will be lost"
echo " "
read -p "Are you sure? " -n 1 -r
echo    # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
  exit 1
fi

echo " "
echo "You answered: Yes! All data will be wiped out! "
echo " "
echo "Size of datadir: " `du -hcs $instances/$ID/data | grep total`
echo " "
read -p "Are you really sure? " -n 1 -r
echo    # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
  exit 1
fi

echo "Wiping out from disk instance $1..."
echo " "
cd $instances
mypwd=`pwd`
if [ $mypwd == $instances ] && [ $ID != "" ]
then
  pwd
  rm $ID
  mv *.$ID $basedir/erased
fi
echo "Done."

